import React, {useState,} from "react";
import {Button, Input, Modal} from "antd";
import UserModel from "../../../model/user";
import Info from "../../../service/info";

const SendUserMsgModal = props => {

    const [txt, setTxt,] = useState('')
    const [title, setTitle,] = useState('')
    const model = new UserModel()
    const sendMsg = () => {
        const user = props.user
        const params = {
            Uid: user.Id,
            Title: title,
            Txt: txt,
        }
        model.sendMsg(params).then(res => {
            console.log("res", res)
            if (res.data.ok === 1) {
                props.onCancel('sendMsg')
                setTxt('')
                setTitle('')
                Info.success('已发送')
            }
        })
    }

    return <Modal
        title="私信"
        visible={props.visible}
        footer={null}
        maskClosable={true}
        onCancel={props.onCancel}
    >

        <Input
            placeholder='私信标题'
            onChange={(e) => setTitle(e.target.value)}
            style={{marginBottom: '16px',}}
        />
        <Input.TextArea
            placeholder='私信正文'
            onChange={(e) => setTxt(e.target.value)}
        />
        
        <Button
            onClick={sendMsg}
        >
            发送
        </Button>
    </Modal>

}

export default SendUserMsgModal